# coding=utf-8

import tkinter as tk
import Frame.FrameTools as fk  # 窗口工具类
from tkinter import ttk
from tkinter import PhotoImage;
import Base.Mina as datashow;
from tkinter import filedialog;
from tkinter import messagebox;
import sys

excel_file = ' ';  # 文件路径
x_attr = '中文名';  # 参数x
y_attr = '采集地(省)';  # 参数y
v_attr = '散点图';  # 视图参数

win = tk.Tk();
win.title("数据可视化")
win.resizable(width=False, height=False)
fk.center_window(win, 600, 200);
# banner 植物标本数据可视化展示
label_logo = tk.Label(win, text='植物标本数据可视化展示', font=("黑体", 30));
label_logo.pack();

# 创建第一个容器
fm1 = tk.Frame(win);
fm1.pack(side=tk.TOP, fill=tk.BOTH)
open_file = tk.Button(fm1, text="1:打开 文件", height=2);
show_data = tk.Button(fm1, text="数据 预览", height=2,command=lambda:datashow.show_data(x_attr,y_attr,v_attr));
photo = PhotoImage(file='../2.png')
img_label = tk.Label(fm1, imag=photo, text="初始工作");
open_file.pack(side=tk.LEFT, padx=120, ipadx=10)
img_label.pack(side=tk.LEFT, padx=6)
show_data.pack(side=tk.LEFT, padx=6, ipadx=10)

# 创建第二个容器
fm2 = tk.Frame(win);
fm2.pack(side=tk.TOP, fill=tk.BOTH)
info_label = tk.Label(fm2, text="可视化步骤>", pady=5, font=("黑体", 15));
info_label.pack(side=tk.LEFT, padx=6);

attr_label = tk.Label(fm2, text="选择属性1:2：", pady=5, font=("黑体", 15));
attr_label.pack(side=tk.LEFT, padx=6);
# 绑定变量
cv = tk.StringVar()
cv2 = tk.StringVar()
com_attr1 = ttk.Combobox(fm2, textvariable=cv)
com_attr2 = ttk.Combobox(fm2, textvariable=cv2)
com_attr1.pack(side=tk.LEFT, padx=6);
com_attr2.pack(side=tk.LEFT, padx=6);

# id 中文名	采集人	采集年份	采集日期	 采集地(省)	采集地(县)	采集海拔(m)	鉴定人	鉴定年份	鉴定日期
# 设置下拉数据
com_attr1["value"] = "中文名"
com_attr2["value"] = ("采集海拔(m)", "采集人", "鉴定人", "鉴定年份", "采集地(省)", "采集地(县)", "采集年份")

# 设置默认指向
com_attr1.current(0)
com_attr2.current(0)
# 创建第三个容器
fm3 = tk.Frame(win);
fm3.pack(side=tk.TOP, fill=tk.BOTH)
info_label2 = tk.Label(fm3, text="可视化步骤>", pady=5, font=("黑体", 15));
info_label2.pack(side=tk.LEFT, padx=6);
attr_label2 = tk.Label(fm2, text="选择视图1:2：", pady=5, font=("黑体", 15));
attr_label2.pack(side=tk.LEFT, padx=6);
cv3 = tk.StringVar()
com_viewer = ttk.Combobox(fm3, textvariable=cv3)
com_viewer["value"] = ("散点图", "线条图", "直方图","散点图3D","区域图")
com_viewer.pack(side=tk.LEFT, padx=10);
com_viewer.current(0)


def showViewer(event):
    print("xxxx")


#
start = tk.Button(win, text="执行可视化", command=lambda: datashow.showViewer(x_attr, y_attr, v_attr));
start.pack(side=tk.BOTTOM, fill='x')


# 绑定事件

def show_com_attr(event):
    print(cv.get())
    print(cv2.get())
    print(cv3.get())
    global x_attr, y_attr, v_attr;
    x_attr = cv.get();
    y_attr = cv2.get();
    v_attr = cv3.get();
    print(type(x_attr))


com_viewer.bind("<<ComboboxSelected>>", show_com_attr)


def fun(event):
    path = filedialog.askopenfilename(title='选择Excel文件', filetypes=[('Excel', '*.xlsx'), ('All Files', '*')])
    messagebox.showinfo("提示", "选择文件为：" + str(path))
    global excel_file;
    excel_file = path;  # excel 文件路径
    print(path);

open_file.bind("<Button-1>", fun);
win.protocol("WM_DELETE_WINDOW", lambda: sys.exit(0));

win.mainloop();
